package com.ybwh.springboot2.controller;

import com.ybwh.springboot2.common.RespData;
import com.ybwh.springboot2.common.annotation.CurrUserId;
import com.ybwh.springboot2.model.po.TenantInfo;
import com.ybwh.springboot2.service.TenantInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;



/**
 * <p>
 * 租户信息控制器
 * </p>
 *
 * @author Fan Beibei
 * @version V1.0
 * @since 2022-12-23 12:04:14
 */
@Slf4j
@Api(tags = "租户信息接口")
@RestController
@RequestMapping("/tenantInfo")
public class TenantInfoController{

    @Autowired
    private TenantInfoService tenantInfoService;


    @ApiOperation(value = "根据ID查询", notes = "")
    @ResponseBody
    @GetMapping("/queryById")
    public RespData<TenantInfo> queryById(@RequestParam("id") Long id) {

        TenantInfo tenantInfo = tenantInfoService.queryById(id);

        return RespData.successResp(tenantInfo);

    }


    @ApiOperation(value = "批量删除", notes = "")
    @ResponseBody
    @PostMapping("/batchDel")
    public RespData<Integer> batchDel(@RequestBody Set<Long> ids, @CurrUserId Long userId) {

        int effectCount = tenantInfoService.softDelByIds(ids, userId);

        return RespData.successResp(effectCount);

    }


    @ApiOperation(value = "新增或更新", notes = "")
    @ResponseBody
    @PostMapping("/addOrUpdate")
    public RespData<Long> addOrUpdate(@RequestBody TenantInfo param, @CurrUserId Long userId) {

        Long id =tenantInfoService.addOrUpdate(param, userId);

        return RespData.successResp(id);

    }


}
